package com.css.devops.rest;

import javax.annotation.Resource;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.css.devops.service.DevopsViewManager;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "Devops：新增或删除Job任务到View视图中")
@RestController
@RequestMapping("${devops-context}/viewManager")
public class DevopsViewManagerResource {

	@Resource(name = "${devops.service.view-manager}")
	private DevopsViewManager devopsViewManager;
	
	@ApiOperation(value = "添加Job到View中")
	@GetMapping("addJobToView/{viewName}/{jobName}")
	public ResponseEntity<String> addJobToView(@PathVariable String viewName,@PathVariable String jobName) {
		try {
			devopsViewManager.addJobToView(viewName, jobName);
		}catch (Exception e) {
			return ResponseEntity.status(HttpStatus.NOT_FOUND).body("添加Job到View中失败!");
		}
		return ResponseEntity.ok("添加Job到View中成功!");
	}
	
	@ApiOperation(value = "移除Job到View中")
	@GetMapping("removeJobFromView/{viewName}/{jobName}")
	public ResponseEntity<String> removeJobFromView(@PathVariable String viewName,@PathVariable String jobName) {
		try {
			devopsViewManager.removeJobFromView(viewName, jobName);
		}catch (Exception e) {
			return ResponseEntity.status(HttpStatus.NOT_FOUND).body("移除View中的Job失败!");
		}
		return ResponseEntity.ok("移除View中的Job成功!");
	}
}
